package com.hulang.sms.sending.bean;

import lombok.Data;

/**
 * Created by Pharaoh on 2018/10/24.
 */
@Data
public class ApiResult<T> {

    /**
     * 返回结果代码
     */

    private int code =0;
    /**
     * 返回结果类型
     */
    //@ApiModelProperty(value = "结果类型", position = 1)
   // private String type;
    /**
     * 具体的错误信息
     */
    //@ApiModelProperty(value = "错误信息", position = 2)
    //private String message;
    /**
     * Exception类
     */
    //@ApiModelProperty(value = "异常类", position = 3)
    //private String exception;
    /**
     * 返回结果数据
     */

    private T data = null;

    /**
     * 是否成功,0表示成功，其他都是失败
     */

    private boolean success = false;



    private String info = "default info";

    public ApiResult<T> success() {
        this.success = true;
        this.code = 1;
        this.info = "default success info";
        return this;
    }
   
    public ApiResult<T> success(T data) {
        this.success();
        this.data = data;
        return this;
    }
    public ApiResult<T> success(String info) {
        this.info = info;
        this.success();
        return this;
    }
    public ApiResult<T> success(T data, String info) {
        this.success();
        this.data = data;
        this.info = info;
        return this;
    }
    @SuppressWarnings("rawtypes")
    public ApiResult failed() {
        this.success = false;
        this.code = 0;
        return this;
    }
    @SuppressWarnings("rawtypes")
    public ApiResult failed(String info) {
        this.failed();
        this.info = info;
        return this;
    }
    /**
     * 无权限的fail
     * @param code
     * @param info
     * @return
     */
    @SuppressWarnings("rawtypes")
    public ApiResult failed(int code,String info) {
    	this.success = false;
    	this.info = info;
    	this.code = code;
    	return this;
    }
    @SuppressWarnings("rawtypes")
    public ApiResult failed(T data, String info) {
        this.failed();
        this.data = data;
        this.info = info;
        return this;
    }
    @SuppressWarnings("rawtypes")
    public ApiResult exception(int code, String info) {
        this.success = false;
        this.code = code;
        this.info = info;
        return this;
    }

}
